package codeRandomThoughts.Test999完全背包;

public class Solution {
    private static int testCompletePack(int[] weight, int[] value, int bagSize) {
        //定义dp数组
        int[] dp = new int[bagSize + 1];
        for (int i = 0; i < weight.length; i++) {
            for (int j = weight[i]; j <= bagSize; j++) {
                dp[j] = Math.max(dp[j], dp[j - weight[i]] + value[i]);
            }
        }

        return dp[bagSize];
    }

    public static void main(String[] args) {
        int[] weight = {1, 3, 4};
        int[] value = {15, 20, 30};
        int bagSize = 4;
        System.out.println(testCompletePack(weight, value, bagSize));
    }
}
